package com.hello.pet.service.system.controller;

import com.hello.pet.common.result.ComResult;
import com.hello.pet.service.system.service.OssService;
import com.hello.pet.service.system.utils.FileUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Api(tags="oss")
@RestController
@RequestMapping("/system/oss")
public class OssController{

    @Autowired
    private OssService ossService;

    @ApiOperation("文件上传")
    @PostMapping("/upload")
    @PreAuthorize("hasAuthority('sys:user:getUser')")
    public ComResult<String> upload(@ApiParam("上传的文件") @RequestPart("file") MultipartFile file) {
        FileUtils.checkFileSize(file.getSize(),200,"M");
        return ComResult.success(ossService.upload(file));
    }
}
